package com.yls.except.util.kuaidiniao;

import com.yls.except.util.Base64;
import com.yls.except.util.ConstantUtil;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map; 

/**
 *
 * 快递鸟短信
 *
 * @技术QQ群: 456320272
 * @copyright: 深圳市快金数据技术服务有限公司
 *
 * 
 * ID和Key请到官网申请：http://www.kdniao.com/ServiceApply.aspx
 */

public class KdApiSMSDemo {
	
	//DEMO
	public static void main(String[] args) {
		KdApiSMSDemo api = new KdApiSMSDemo();
		try {
			String result = api.getSMSSendRecordByJson();
			System.out.print(result);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	//请求url
	private String ReqURL="http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx";	
 
	/**
     * Json方式 短信发送
	 * @throws Exception 
     */
	public String getSMSSendRecordByJson() throws Exception{
		String requestData= "{'Detail':[{'ReceiverName':'张三','ReceiverMobile':'15814460948'}],'MemberID':'123456','CallBack':''}";
		Map<String, String> params = new HashMap<String, String>();
		params.put("RequestData", KdApiCreateOrderDemo.urlEncoder(requestData, "UTF-8"));
		params.put("EBusinessID", ConstantUtil.EBUSINESSID);
		params.put("RequestType", "8101");
		String dataSign=KdApiCreateOrderDemo.encrypt(requestData, ConstantUtil.APPKEY, "UTF-8");
		params.put("DataSign", KdApiCreateOrderDemo.urlEncoder(dataSign, "UTF-8"));
		params.put("DataType", "2");
		
		String result=KdApiCreateOrderDemo.sendPost(ReqURL, params);
		
		//根据公司业务处理返回的信息......
		
		return result;
	}
 
 
	/**
     * Json方式 短信模板
	 * @throws Exception 
     */
	public String getSMSTemplateByJson() throws Exception{
		String requestData= "{'Detail':[{'TemplateType':'6','MessageTemplate':'短信模板','IsOpen':0}],'MemberID':'123456'}";
		Map<String, String> params = new HashMap<String, String>();
		params.put("RequestData", KdApiCreateOrderDemo.urlEncoder(requestData, "UTF-8"));
		params.put("EBusinessID", ConstantUtil.EBUSINESSID);
		params.put("RequestType", "8102");
		String dataSign=KdApiCreateOrderDemo.encrypt(requestData, ConstantUtil.APPKEY, "UTF-8");
		params.put("DataSign", KdApiCreateOrderDemo.urlEncoder(dataSign, "UTF-8"));
		params.put("DataType", "2");
		
		String result=KdApiCreateOrderDemo.sendPost(ReqURL, params);
		
		//根据公司业务处理返回的信息......
		
		return result;
	}
 
	/**
     * Json方式 短信黑名单
	 * @throws Exception 
     */
	public String getSMSBlackByJson() throws Exception{
		String requestData= "{'Detail':[{'Mobile':'15814460948','IsBlack':0}],'MemberID':'123456'}";
		Map<String, String> params = new HashMap<String, String>();
		params.put("RequestData", KdApiCreateOrderDemo.urlEncoder(requestData, "UTF-8"));
		params.put("EBusinessID", ConstantUtil.EBUSINESSID);
		params.put("RequestType", "8103");
		String dataSign=KdApiCreateOrderDemo.encrypt(requestData, ConstantUtil.APPKEY, "UTF-8");
		params.put("DataSign", KdApiCreateOrderDemo.urlEncoder(dataSign, "UTF-8"));
		params.put("DataType", "2");
		
		String result=KdApiCreateOrderDemo.sendPost(ReqURL, params);
		
		//根据公司业务处理返回的信息......
		
		return result;
	}
}
